#if !defined(AFX_PANELTREEBROWSER_H__ED063BD6_1FEA_4541_A216_BF7DA4DF4727__INCLUDED_)
#define AFX_PANELTREEBROWSER_H__ED063BD6_1FEA_4541_A216_BF7DA4DF4727__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// PanelTreeBrowser.h : header file
//

#include "Controls/TreeCtrlReport.h"

class CProceduralCreationDialog;

class CObjectBrowserFileScanner
{
public:

	static const uint32 kDefaultAllocFileCount = 5000;

	CObjectBrowserFileScanner();
	void Scan( const CString& searchSpec );
	bool HasNewFiles();
	void GetScannedFiles( CFileUtil::FileArray &files );
	bool IsScanningForFiles();

protected:

	CString								m_searchSpec;
	CryCriticalSection		m_lock;
	CFileUtil::FileArray	m_filesForUser;
	CFileUtil::FileArray	m_files;
	bool									m_bScanning;
	bool									m_bNewFiles;
};

/////////////////////////////////////////////////////////////////////////////
// CPanelTreeBrowser dialog
class CPanelTreeBrowser : public CXTResizeDialog,public IEditorNotifyListener
{
// Construction
public:

	enum EItemNodeType
	{
		eItemNodeType_File,
		eItemNodeType_Folder
	};

	typedef Functor1<CString>									TSelectCallback;
	typedef std::map<CString,std::pair<CString,EItemNodeType>>	TSearchSpecAndItemNameMap;
	typedef std::map<CString,CFileUtil::FileArray>				TFileHistory;

	CPanelTreeBrowser(CWnd* pParent = NULL);   // standard constructor
	virtual ~CPanelTreeBrowser();

// Dialog Data
	enum { IDD = IDD_PANEL_TREEBROWER };

	enum EFlags {
		NO_DRAGDROP = 0x001,			// Disable drag&drop of items to view,
		NO_PREVIEW = 0x002,
		SELECT_ONCLICK = 0x004, // Select callback when item is selected in tree view.
	};

	enum {
		DEFAULT_DIALOG = 0,
		ME_SELECTION_DIALOG = 1, // Custom Modular Editor dialog
		ME_REPLACE_DIALOG = 2, // Custom Modular Editor dialog
	};

	void	Create( TSelectCallback &cb,const CString &searchSpec,CWnd *parent,int flags=0 );
	void	SetSelectCallback( TSelectCallback &cb ) { m_selectCallback = cb; };
	void	SetDragAndDropCallback( TSelectCallback &cb ) { m_dragAndDropCallback = cb; };
	void	SelectFile( const CString &filename );
	void	AddPreviewPanel();
	int		GetDialogType(){return m_dialogType;};
	void	SetDialogType(int dialogTypeFlag){m_dialogType=dialogTypeFlag;};
	void SetEnable( bool bEnable);
	// This method should be only used by the Modular Editor Tool.
	void	AddModularEditorPreviewPanel(CProceduralCreationDialog *procDialog, CRollupCtrl *previewCtrl);
	void	SetSearchSpec( const CString &searchSpec ) { m_searchSpec=searchSpec; };
	CString	GetSearchSpec() { return m_searchSpec; } ;
	void	Refresh( bool bReloadFiles );

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CPanelTreeBrowser)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	struct FilesInfo
	{
		std::vector<CString> files;
	};

	virtual void OnOK() {};
	virtual void OnCancel() {};

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnDestroy();
	afx_msg void OnCustomBtnClick();
	afx_msg void OnFilterChange();
	DECLARE_MESSAGE_MAP()

	//////////////////////////////////////////////////////////////////////////
	virtual void OnEditorNotifyEvent( EEditorNotifyEvent event );
	//////////////////////////////////////////////////////////////////////////

	CString	GetSelectedFile();
	void AcceptFile( const CString &file,bool bDragAndDrop );

	void FillEntityScripts( bool bReload );
	void FillDBLibrary( EDataBaseItemType dbType );
	void FillPrefabs();
	void FillTreeWithFiles( CFileUtil::FileArray &files );
	void UpdateFileCountLabel();
	void SortTree();
	void SortItem( HTREEITEM hParent );
	void ClearTreeItems();
	void ReselectLastSelectedTreeItem();
	void LoadFilesFromScanning();
	void OnReload();

	void OnSelectionChanged( CTreeItemRecord *pRec );
	void OnDragAndDrop( CTreeItemRecord *pRec );
	void OnDblclkBrowserTree( CTreeItemRecord *pRec );

	//////////////////////////////////////////////////////////////////////////

private:

	int m_flags;
	int m_dialogType;

	CObjectBrowserFileScanner	m_fileScanner;
	CImageList m_cImageList;
	StdMap<HTREEITEM,CString> m_itemsMap;
	std::map<CString,HTREEITEM,stl::less_stricmp<CString> > m_fileToItem;

	CTreeCtrlReport m_treeCtrl;
	
	CString m_path;
	CString m_searchSpec;
	// map of spec and file name, static so we can use it between panel switches
	static TSearchSpecAndItemNameMap m_lastSelectedItemNames;

	CString m_draggedFile;
	CEdit m_filter;
	
	CCustomButton m_reloadBtn;
	CCustomButton m_customBtn;

	TSelectCallback m_selectCallback;
	TSelectCallback m_dragAndDropCallback;

	UINT m_nNumFiles;

	class CPanelPreview *m_panelPreview;
	int m_panelPreviewId;

	bool m_bDragDropEnabled;
	bool m_bSelectOnClick;

	static TFileHistory			sm_fileHistory;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_PANELTREEBROWSER_H__ED063BD6_1FEA_4541_A216_BF7DA4DF4727__INCLUDED_)
